<?php
  Loader::loadFile('config.php', 'modules/IGallery');
  /**
  * initialise module
  *
  */
  function IGallery_init() {

    //Create upload module path   
    createGalleryFolder();
    
    return true;
  }

  function IGallery_delete() {

/*
    $dir = "./resource/gallery_upload/";
    
    //Remove folder 
    if (!file_exists($dir)){ 
      return true; 
    }
    
    //Remove file
    if (!is_dir($dir) || is_link($dir)){
      return unlink($dir); 
    }
    
    //Recursive remove file & folder   
    foreach (scandir($dir) as $item) { 
        if ($item == '.' || $item == '..') continue; 
        if (!deleteDirectory($dir . "/" . $item)) { 
            chmod($dir . "/" . $item, 0777); 
            if (!deleteDirectory($dir . "/" . $item)) return false; w
        }; 
    } 
    rmdir($dir); 
*/
    
    return true;
  }



  function createGalleryFolder(){
  
    Loader::loadFile('config.php', "modules/IGallery");
    
    //Create root path
    if(!is_dir(UPLOAD_FILES_MAINPATH)){
      mkdir(UPLOAD_FILES_MAINPATH, 0777);
      
      //copy .htaccess and index.html into resource directory (root path)
      copy(HTACCESS_PATH, UPLOAD_FILES_MAINPATH_HTACCESS_PATH);
      copy(HTML_BLANK_PATH, UPLOAD_FILES_MAINPATH_HTML_BLANK_PATH);          
    }

    //Create gallery path
    if(!is_dir(UPLOAD_FILES_GALLAERY)){
      mkdir(UPLOAD_FILES_GALLAERY, 0777);
      
      //copy .htaccess and index.html into resource directory (root path)
      copy(HTACCESS_PATH, UPLOAD_FILES_GALLAERY_HTACCESS);
      copy(HTML_BLANK_PATH, UPLOAD_FILES_GALLAERY_BLANK_HTML);          
    }    
     
      
      
  }
